﻿namespace Charades.Web
{
	using System.Web.Mvc;
	using System.Web.Routing;
	using System.Collections.Generic;

	public class RouteConfig
	{
		public static void RegisterRoutes(RouteCollection routes)
		{
			routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

			var routesHome = new Dictionary<string, string>()
				                 {
					                 { "About", "about" },
					                 { "Feed", "feed" },
					                 { "LoadFeed", "loadFeed" },
					                 { "UploadImage", "upload" },
					                 { "ChangeName", "changeName" },
					                 { "CheckRoom", "checkRoom" }
				                 };

			foreach (var route in routesHome)
			{
				routes.MapRoute(
					name: route.Key,
					url: route.Value,
					defaults: new { controller = "Home", action = route.Key });
			}

			var routesAccount = new Dictionary<string, string>()
				                    {
					                    { "Login", "login" },
					                    { "LogOff", "logoff" },
					                    { "LoginCallback", "loginCallback" },
					                    { "ExternalLogin", "externalLogin" }
				                    };

			foreach (var route in routesAccount)
			{
				routes.MapRoute(
					name: route.Key,
					url: route.Value,
					defaults: new { controller = "Account", action = route.Key });
			}

			var routesPages = new[] { "Logon", "Profile", "Intro", "Game" };

			foreach (var name in routesPages)
			{
				routes.MapRoute(
					name: name,
					url: "page/" + name.ToLower(),
					defaults: new { controller = "Home", action = name });
			}

			routes.MapRoute(
				name: "Picture",
				url: "{id}",
				defaults: new { controller = "Home", action = "Picture", id = UrlParameter.Optional },
				constraints: new { id = @"^[a-zA-Z0-9]{8}$" });

			routes.MapRoute(
				name: "DefaultWithRoomId",
				url: "{id}",
				defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
				constraints: new { id = @"^[a-zA-Z0-9]{5}$" });

			routes.MapRoute(
				name: "Default",
				url: "{controller}/{action}/{id}",
				defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional });
		}
	}
}
